package com.timoon.component.panel.common.utils;

import java.util.Map;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;

import com.googlecode.wicket.jquery.ui.Options;

public class ValidateClassModifier{
	private static final long serialVersionUID = -6667852733376247697L;

	private static String ATTRIBUTE="class";
	
	/**
	 * 
	 * @param component
	 * @param isRemain	是否保留之前class的值
	 * @param map
	 */
	public static void validate(Component component,boolean isRemain,Map<String,String> map) {
		// TODO Auto-generated constructor stub
		String oldClass=component.getMarkupAttributes().getKey("class");
		
		StringBuffer replace=new StringBuffer("validate[");
		Options o=new Options();
		
		if(map.containsKey("required")){
			replace.append("required,");
		}
		if(map.containsKey("minSize")){
			replace.append("minSize["+map.get("minSize")+"],");
		}
		if(map.containsKey("maxSzie")){
			replace.append("minSize["+map.get("minSize")+"],");
		}
		if(map.containsKey("email")){
			replace.append("custom[email],");
		}
		replace.deleteCharAt(replace.length()-1);
		replace.append("]");
		
		component.add(new AttributeModifier(ATTRIBUTE, replace));
	}

}
